package register;

import java.util.Scanner;

public class User {
    private String name;
    private String password;
    private String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 注册
     */
    public void register() {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入账号名（要求6-20位字母、数字、下划线组成）");
        while (true) {
            String name = scan.next();
            if (name.matches("^[a-zA-Z0-9_]{6,20}$")) {
                this.name = name;
                break;
            }
            System.out.println("账号名不符合要求，请重新输入");
        }

        System.out.println("请输入密码（必须包含大小写字母和数字的组合，不能使用特殊字符，长度不少于6位）");
        while (true) {
            String password = scan.next();
            if (password.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$")) {
                this.password = password;
                break;
            }
            System.out.println("密码不符合要求，请重新输入");
        }
        System.out.println("请确认密码");
        while (true) {
            String password2 = scan.next();
            if (password2.equals(this.password)) {
                break;
            }
            System.out.println("与第一次密码不同，请重新输入");
        }
        System.out.println("请输入电子邮箱");
        while (true) {
            String email = scan.next();
            if (email.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")) {
                this.email = email;
                break;
            }
            System.out.println("错误电子邮箱，请重新输入");
        }
        System.out.println("注册成功");
    }

    public static void main(String[] args) {
        User user = new User();
        user.register();
    }

}
